<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>lwIP: Semaphores</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">lwIP
   &#160;<span id="projectnumber">2.1.2</span>
   </div>
   <div id="projectbrief">Lightweight IP stack</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__sys__sem.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Semaphores<div class="ingroups"><a class="el" href="group__lwip.html">lwIP</a> &raquo; <a class="el" href="group__sys__layer.html">Porting (system abstraction layer)</a> &raquo; <a class="el" href="group__sys__os.html">OS abstraction layer</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:gaf99da9e34a71855285c535183133dfde"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__infrastructure__errors.html#gaf02d9da80fd66b4f986d2c53d7231ddb">err_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__sem.html#gaf99da9e34a71855285c535183133dfde">sys_sem_new</a> (sys_sem_t *sem, u8_t count)</td></tr>
<tr class="separator:gaf99da9e34a71855285c535183133dfde"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaaf800273061fcc3f8200fd4e1b9ca875"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__sem.html#gaaf800273061fcc3f8200fd4e1b9ca875">sys_sem_signal</a> (sys_sem_t *sem)</td></tr>
<tr class="separator:gaaf800273061fcc3f8200fd4e1b9ca875"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga8d364c5037778acb21c3df675db81b4f"><td class="memItemLeft" align="right" valign="top">u32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__sem.html#ga8d364c5037778acb21c3df675db81b4f">sys_arch_sem_wait</a> (sys_sem_t *sem, u32_t timeout)</td></tr>
<tr class="separator:ga8d364c5037778acb21c3df675db81b4f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga83b781f96c30e915c752065a757da283"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__sem.html#ga83b781f96c30e915c752065a757da283">sys_sem_free</a> (sys_sem_t *sem)</td></tr>
<tr class="separator:ga83b781f96c30e915c752065a757da283"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga09a6c052ddaf799139efc56adfa087e4"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__sem.html#ga09a6c052ddaf799139efc56adfa087e4">sys_sem_valid</a> (sys_sem_t *sem)</td></tr>
<tr class="separator:ga09a6c052ddaf799139efc56adfa087e4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga42a2ab32afbf41a4146a9d135224ef33"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__sem.html#ga42a2ab32afbf41a4146a9d135224ef33">sys_sem_set_invalid</a> (sys_sem_t *sem)</td></tr>
<tr class="separator:ga42a2ab32afbf41a4146a9d135224ef33"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Semaphores can be either counting or binary - lwIP works with both kinds. Semaphores are represented by the type "sys_sem_t" which is typedef'd in the sys_arch.h file. Mailboxes are equivalently represented by the type "sys_mbox_t". Mutexes are represented by the type "sys_mutex_t". lwIP does not place any restrictions on how these types are represented internally. </p>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga8d364c5037778acb21c3df675db81b4f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga8d364c5037778acb21c3df675db81b4f">&#9670;&nbsp;</a></span>sys_arch_sem_wait()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">u32_t sys_arch_sem_wait </td>
          <td>(</td>
          <td class="paramtype">sys_sem_t *&#160;</td>
          <td class="paramname"><em>sem</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">u32_t&#160;</td>
          <td class="paramname"><em>timeout</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Blocks the thread while waiting for the semaphore to be signaled. If the "timeout" argument is non-zero, the thread should only be blocked for the specified time (measured in milliseconds). If the "timeout" argument is zero, the thread should be blocked until the semaphore is signalled.</p>
<p>The return value is SYS_ARCH_TIMEOUT if the semaphore wasn't signaled within the specified time or any other value if it was signaled (with or without waiting). Notice that lwIP implements a function with a similar name, <a class="el" href="sys_8h.html#a84e7e4bc00255aee84e6e7289a985703">sys_sem_wait()</a>, that uses the <a class="el" href="group__sys__sem.html#ga8d364c5037778acb21c3df675db81b4f">sys_arch_sem_wait()</a> function.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">sem</td><td>the semaphore to wait for </td></tr>
    <tr><td class="paramname">timeout</td><td>timeout in milliseconds to wait (0 = wait forever) </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>SYS_ARCH_TIMEOUT on timeout, any other value on success </dd></dl>

</div>
</div>
<a id="ga83b781f96c30e915c752065a757da283"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga83b781f96c30e915c752065a757da283">&#9670;&nbsp;</a></span>sys_sem_free()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sys_sem_free </td>
          <td>(</td>
          <td class="paramtype">sys_sem_t *&#160;</td>
          <td class="paramname"><em>sem</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Deallocates a semaphore. </p><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">sem</td><td>semaphore to delete </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="gaf99da9e34a71855285c535183133dfde"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaf99da9e34a71855285c535183133dfde">&#9670;&nbsp;</a></span>sys_sem_new()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__infrastructure__errors.html#gaf02d9da80fd66b4f986d2c53d7231ddb">err_t</a> sys_sem_new </td>
          <td>(</td>
          <td class="paramtype">sys_sem_t *&#160;</td>
          <td class="paramname"><em>sem</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">u8_t&#160;</td>
          <td class="paramname"><em>count</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Create a new semaphore Creates a new semaphore. The semaphore is allocated to the memory that 'sem' points to (which can be both a pointer or the actual OS structure). The "count" argument specifies the initial state of the semaphore (which is either 0 or 1). If the semaphore has been created, ERR_OK should be returned. Returning any other error will provide a hint what went wrong, but except for assertions, no real error handling is implemented.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">sem</td><td>pointer to the semaphore to create </td></tr>
    <tr><td class="paramname">count</td><td>initial count of the semaphore </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>ERR_OK if successful, another err_t otherwise </dd></dl>

</div>
</div>
<a id="ga42a2ab32afbf41a4146a9d135224ef33"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga42a2ab32afbf41a4146a9d135224ef33">&#9670;&nbsp;</a></span>sys_sem_set_invalid()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sys_sem_set_invalid </td>
          <td>(</td>
          <td class="paramtype">sys_sem_t *&#160;</td>
          <td class="paramname"><em>sem</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Invalidate a semaphore so that <a class="el" href="group__sys__sem.html#ga09a6c052ddaf799139efc56adfa087e4">sys_sem_valid()</a> returns 0. ATTENTION: This does NOT mean that the semaphore shall be deallocated: <a class="el" href="group__sys__sem.html#ga83b781f96c30e915c752065a757da283">sys_sem_free()</a> is always called before calling this function! This may also be a define, in which case the function is not prototyped. </p>

</div>
</div>
<a id="gaaf800273061fcc3f8200fd4e1b9ca875"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaaf800273061fcc3f8200fd4e1b9ca875">&#9670;&nbsp;</a></span>sys_sem_signal()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sys_sem_signal </td>
          <td>(</td>
          <td class="paramtype">sys_sem_t *&#160;</td>
          <td class="paramname"><em>sem</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Signals a semaphore </p><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">sem</td><td>the semaphore to signal </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ga09a6c052ddaf799139efc56adfa087e4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga09a6c052ddaf799139efc56adfa087e4">&#9670;&nbsp;</a></span>sys_sem_valid()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int sys_sem_valid </td>
          <td>(</td>
          <td class="paramtype">sys_sem_t *&#160;</td>
          <td class="paramname"><em>sem</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Returns 1 if the semaphore is valid, 0 if it is not valid. When using pointers, a simple way is to check the pointer for != NULL. When directly using OS structures, implementing this may be more complex. This may also be a define, in which case the function is not prototyped. </p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
  </ul>
</div>
</body>
</html>
